<?php
namespace Home\Widget;
use Think\Controller;
/*
 *分类树挂件
 *@author  <!-- blakefan 1621743934@qq.com-->
 */
class TypeTreeWidget extends Controller
{
    
   public function index()
   {
   		//获取所有父级类目
   		$temp=getListCat();
   		if (count($temp)>0)
   		{
   			$typeBrand=M('type_brand');
   			$brand=M('brand');
   			foreach($temp as $key=>&$value)
   			{
   				if($value['level']==0){ continue;}
   				$brandids=$typeBrand->cache(true)->where('typeid=%d',$key)->getField('brandid',true);
   				if(!empty($brandids))
   				{
   					$map['brandid']=array('in',$brandids);
   					$value['brands']=M('brand')->where($map)->getField('brandid,brandname');
   				}
   				
   			}
   		}
         
   		$this->assign('typetree',$temp);
   		$this->display('TypeTree:index');
   }
}